package com.meixiang.dialog;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.meixiang.R;
import com.meixiang.activity.account.managers.BindBankCardActivity;
import com.meixiang.activity.account.managers.ManageBankCardActivity;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.util.AbToastUtil;

import org.json.JSONObject;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 管理银行卡Dialog
 *
 * @author LZRUI
 */
public class ManageBankDialogFragment extends BaseDialogFragment {

    public static String TAG = "ManageBankDialogFragment";
    public ManageBankDialogFragment() {
    }

    public static ManageBankDialogFragment newInstance() {
        return new ManageBankDialogFragment();
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    protected int setFragmentViewId() {
        return R.layout.dialog_manage_bank;
    }


    @Override
    protected void initView(View rootView) {
        ButterKnife.bind(this, rootView);
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.tv_change_bind, R.id.tv_cancel_bind, R.id.tv_option})
    public void onClick(View view) {
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            // 更换绑定
            case R.id.tv_change_bind:
                dismiss();
                bundle.putInt("key", 1);
                startActivity(BindBankCardActivity.class, bundle);
                break;
            // 取消绑定
            case R.id.tv_cancel_bind:
                new AlertDialogFragment.Builder()
                        .setContentText("你确定要取消绑定？")
                        .setLeftBtnText("确认").setLeftClickCallBack(new AlertDialogFragment.LeftClickCallBack() {
                    @Override
                    public void dialogLeftBtnClick() {
                        getBankBind();
//
                        dismiss();

                    }
                }).setRightBtnText("取消")
                        .build()
                        .show(getFragmentManager(), AlertDialogFragment.TAG);
                break;
            // 取消
            case R.id.tv_option:

                break;
        }
    }
    /*
 *
 * 银行卡管理－解除绑定API
 * **/
    private void getBankBind(){
        Intent intent = new Intent(getActivity(),ManageBankCardActivity.class);
                     //   intent.putExtra("cancel_bind","2");//cancel_bind
                        startActivity(intent);
        //getActivity().finish();
        HttpUtils.post(Config.MY_ACCOUNT_BANKRELIEVE,null, new HttpCallBack(getActivity()) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                if (code.equals("0")){//Tool.changeBankAccount(bankaccount)
                    if (code.equals("0")){
                        AbToastUtil.showToast(getActivity(),message);
                    }else {
                        AbToastUtil.showToast(getActivity(),message);
                    }

                }else {
                    AbToastUtil.showToast(getActivity(),message);
                }
            }

            @Override
            public void onError(String code, String message) {
                AbToastUtil.showToast(getActivity(),message);
            }
        });



    }


}
